﻿(function () {

    layui.use(["layer", "jquery", "table", "form", "laydate"], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        $(document).ready(function () {
            $("#btn-Search-OK").click(onSearchBtnClick);
        });

        var currentDate = moment().format("YYYY-MM-DD");
        if (moment().get("hours") < 15) {
            currentDate = moment().add(-1, "days").format("YYYY-MM-DD");
        }
        laydate.render({
            elem: '#txt-Search-Date',
            value: currentDate,
            isInitValue: true,
            showBottom: false
        });

        function getTableQueryParam() {
            return {
                Date: $("#txt-Search-Date").val(),
                Name: $("#txt-Search-Name").val()
            };
        }

        table.render({
            elem: "#FeeTable",
            url: "/Fee/List",
            height: "full-68", // (10 + 38 + 10 + 10)
            page: false,
            method: "POST",
            where: getTableQueryParam(),
            even: true,
            totalRow: true,
            parseData: function (res) {
                //console.log(res);
                return {
                    "code": res.Success == true ? 0 : -1,
                    "msg": res.Msg,
                    "count": res.Count,
                    "data": res.Data,
                    "totalRow": {
                        count: res.Total
                    }
                };
            },
            cols: [[
                { type: 'numbers', title: 'No.', width: 60, fixed: 'center', totalRow: '{{= d.TOTAL_ROW.count }}' }
                , { field: "Phone", width: 120, align: "center", title: "手机号码" }
                , { field: "Name", width: 100, align: "center", title: "姓名" }
                , { field: "Date", width: 120, align: "center", title: "日期" }
                , { field: "OrderProfitFee", width: 120, align: "center", title: "订单利润", totalRow: true }
                , { field: "ShopManagerFee", width: 120, align: "center", title: "店长管理费", totalRow: true }
                , { field: "BoundFee", width: 120, align: "center", title: "平台分红", totalRow: true }
                , { field: "ConsignmentSaleFee", width: 120, align: "center", title: "寄售服务费" }
                , { align: "center", title: "操作", toolbar: "#ToolBar-Fee" }
            ]]
        });

        function onSearchBtnClick() {
            table.reloadData("FeeTable", {
                where: getTableQueryParam()
            });
        }
    });

})();